package com.zige.zige.view;

import android.content.Context;
import android.graphics.Color;
import android.os.CountDownTimer;
import android.widget.Button;
import android.widget.ImageView;

import com.zige.zige.R;


/**
 * Created by Fei on 2015/11/10.
 */
public class TimerButton extends CountDownTimer {

    private Button button;
    private ImageView imageView;
    private Context context;

    public TimerButton(Context context, long millisInFuture, long countDownInterval, Button button, ImageView imageView) {
        super(millisInFuture, countDownInterval);
        this.button=button;
        this.imageView = imageView;
        this.context = context;
    }

    @Override
    public void onTick(long millisUntilFinished) {
//        button.setBackgroundColor(Color.parseColor("#999999"));
        button.setClickable(false);
        imageView.setClickable(false);
        button.setTextColor(Color.GRAY);
        if (imageView != null) {
            imageView.setImageResource(R.drawable.refresh_no);
        }
        button.setText(millisUntilFinished / 1000 + "s");
    }

    @Override
    public void onFinish() {
        button.setText("重新发送");
        button.setTextColor(context.getResources().getColor(R.color.color_0099ff));
        if (imageView != null) {
            imageView.setImageResource(R.drawable.code_refresh);
        }
        button.setClickable(true);
        imageView.setClickable(true);
//        button.setBackgroundColor(Color.parseColor("#ffc945"));
    }
}
